#include "Skybox.h"
#include <GL/glew.h>
#include <GL\glut.h>

#include "Wall.h"

SkyBox::SkyBox()
{
}

SkyBox::SkyBox(float positionX,float positionY,float positionZ,
	float scaleX,float scaleY, float scaleZ,
	unsigned int _texId[6])
{
	setPosition(positionX,positionY,positionZ);
	setScale(scaleX,scaleY,scaleZ);

	for (int i = 0; i < 6; i++)
	{
		texId[i] = _texId[i];
	}
}

SkyBox::SkyBox(Vector3f& Position, Vector3f& Scale, unsigned int _texId[6])
{
	setPosition(Position);
	setScale(Scale);

	for (int i = 0; i < 6; i++)
	{
		texId[i] = _texId[i];
	}
}

void SkyBox::Draw(void)
{
	glPushMatrix();
	glColor3f(1.0f,1.0f,1.0f);
	glTranslatef(position[0],position[1],position[2]);
	glScalef(scale[0],scale[1],scale[2]);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texId[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	
	glEnd();
	glBegin(GL_QUADS);
	
	//Top Face
	glNormal3f(0.0, -1.0f, 0.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);	

	glEnd();

	glBindTexture(GL_TEXTURE_2D, texId[1]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBegin(GL_QUADS);	

	//Bottom face
	glNormal3f(0.0, 1.0f, 0.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);

	glEnd();

	glBindTexture(GL_TEXTURE_2D, texId[2]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBegin(GL_QUADS);	

	//Left face
	glNormal3f(1.0, 0.0f, 0.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);	

	glEnd();

	glBindTexture(GL_TEXTURE_2D, texId[3]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBegin(GL_QUADS);	

	//Right face
	glNormal3f(-1.0, 0.0f, 0.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);

	glEnd();

	glBindTexture(GL_TEXTURE_2D, texId[4]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBegin(GL_QUADS);

	//Front face
	glNormal3f(0.0, 0.0f, 1.0f);	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 2);

	glEnd();

	glBindTexture(GL_TEXTURE_2D, texId[5]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBegin(GL_QUADS);
	//Back face
	glNormal3f(0.0, 0.0f, -1.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(UNIT_SIZE / 2, -UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-UNIT_SIZE / 2, UNIT_SIZE / 2, -UNIT_SIZE / 2);

	glEnd();

	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
};
